#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
        int stk[1000],t=-1;
        vector<int>has(1e5);
        vector<int>ans;
        for(int i=0;i<nums2.size();i++)
        {
            while(t>=0&&stk[t]<=nums2[i])t--;
            if(t>=0)
            {
                has[nums2[i]]=stk[t];
            }
            else has[nums2[i]]=-1;
            stk[++t]=nums2[i];
        }
        for(int i=0;i<nums1.size();i++)ans.push_back(has[nums1[i]]);
        return ans;
    }
};